package handle

import (
	"github.com/vansante/go-ffprobe"
	"mgs/global"
	"mgs/handle/api"
	"net/http"
	"time"
)

// https://ffmpeg.org/ffprobe.html
// ffprobe 流媒体的分析工具，可以查看流媒体中包含的容器，以及容器中包含的流媒体的格式和类型。
// 测试地址 http://localhost:9000/v1/video/probe?url=https://lf9-cdn-tos.bytecdntp.com/cdn/expire-1-M/byted-player-videos/1.0.0/xgplayer-demo-720p.mp4

func VideoProbe(rw http.ResponseWriter, r *http.Request) {
	url := r.FormValue("url")
	if url == "" {
		api.Failed(rw, "Url Missing")
		return
	}
	var ffp = global.CONFIG.System.Ffprobe
	if len(ffp) > 0 {
		ffprobe.SetFFProbeBinPath(ffp)
	}
	data, err := ffprobe.GetProbeData(url, 120000*time.Millisecond)
	if err != nil {
		api.Failed(rw, err.Error())
		return
	}

	api.Success(rw, data)
	return
}
